home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / runtime / ml_os.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  6.2 KB  |  257 lines

  1. /* ml_os.h
  2.  *
  3.  * COPYRIGHT (c) 1990 by AT&T Bell Laboratories.
  4.  *
  5.  * OS dependent definitions (to make things look like 4.3bsd)
  6.  */
  7.  
  8. #ifndef _ML_OS_
  9. #define _ML_OS_
  10.  
  11. #ifdef THINK_C
  12. #include <time.h>
  13. #else
  14. #include <sys/types.h>
  15. #endif THINK_C
  16.  
  17. #ifdef V9
  18. struct timeval {
  19.     unsigned long   tv_sec;         /* seconds */
  20.     long            tv_usec;        /* and microseconds */
  21. };
  22. #endif
  23.  
  24. #ifdef HPUX
  25. #include <time.h>
  26. #endif
  27.  
  28. /* the return type for signal handlers */
  29. #if defined(VAX) || defined(RISCos) || defined(MACH) || defined(SGI) || defined(AIX) || defined(AUX) || defined(DYNIX)
  30. typedef int SIGH_RET_TYPE;
  31. #else
  32. typedef void SIGH_RET_TYPE;
  33. #endif
  34.  
  35. #ifdef HPUX
  36. #define SIGWINCH    SIGWINDOW
  37. #define SETSIG(sig, h, mask)    {    \
  38.     struct sigvec svec;            \
  39.     svec.sv_mask = (mask);        \
  40.     svec.sv_onstack = 0;        \
  41.     svec.sv_handler = (h);        \
  42.     sigvector ((sig), &svec, 0);    \
  43.   }
  44. #else /* !HPUX */
  45. #if defined(V9) 
  46. #define SETSIG(sig, h, mask)    {    \
  47.     signal(sig, h);            \
  48.   }
  49. #else /* !HPUX && !V9 */
  50. #if defined(AIX)
  51. #define SETSIG(sig, h, mask) {        \
  52.     struct sigaction siga;        \
  53.     (void)sigfillset(&siga.sa_mask);    \
  54.     siga.sa_flags = 0;            \
  55.     siga.sa_handler = (void (*)(int))h; \
  56.     (void)sigaction(sig,&siga,NULL);    \
  57.     }
  58. #else
  59. #ifdef THINK_C
  60. #define SETSIG(sig, h, mask)    {    \
  61.     e_signal(sig, h);            \
  62.   }
  63. #else /* [e] !HPUX && !V9 & !THINK_C */
  64. #define SETSIG(sig, h, mask)    {    \
  65.     struct sigvec svec;            \
  66.     svec.sv_mask = (mask);        \
  67.     svec.sv_onstack = 0;        \
  68.     svec.sv_handler = (h);        \
  69.     sigvec ((sig), &svec, 0);        \
  70.   }
  71. #endif THINK_C 
  72. #endif V9 
  73. #endif HPUX
  74. #endif
  75.  
  76. /* Signal name and code for initiation of garbage-collection */
  77. #ifdef M68
  78. #if defined(HPUX) || defined(AUX)
  79. #define     GC_SIG       SIGILL
  80. #define     GC_CODE      7
  81. #endif
  82. #if defined(FPE_TRAPV_TRAP)
  83. #define     GC_SIG       SIGFPE
  84. #define     GC_CODE      FPE_TRAPV_TRAP
  85. #endif
  86. #if defined(NeXT)
  87. #define     GC_SIG       SIGFPE
  88. #define     GC_CODE      0x1c    /* TRAPV [cpTRAPcc TRAPcc] instr */
  89. #endif
  90. #if defined(MORE)
  91. #define     GC_SIG       SIGFPE
  92. #define     GC_CODE      FPE_INTOVF_TRAP
  93. #endif
  94. #endif
  95.  
  96. #if defined(VAX) && defined(V9)
  97. #define FPE_INTOVF_TRAP K_INTOVF
  98. #endif
  99.  
  100. /* In Mach386, sc_pc is called sc_eip */
  101. #if defined(I386) && defined(MACH)
  102. #define sc_pc    sc_eip
  103. #endif
  104.  
  105. /* miscellaneous */
  106. #if defined(HPUX) || defined(AUX) || defined(THINK_C)
  107. #define bcopy(src, dst, len)    (memcpy((dst), (src), (len)))
  108. #define bzero(dst, len)        (memset((dst), 0, (len)))
  109. #endif
  110.  
  111. /* file-descriptor-sets for select() system call */
  112. #ifndef FD_SET
  113. #define    FD_SET(n, p)    ((p)->fds_bits[(n)/32] |= (1 << ((n) % 32)))
  114. #define    FD_CLR(n, p)    ((p)->fds_bits[(n)/32] &= ~(1 << ((n) % 32)))
  115. #define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/32] & (1 << ((n) % 32)))
  116. #define    FD_ZERO(p)    (bzero((char *)(p), sizeof(*(p))))
  117. #endif
  118.  
  119. /* cache-flushing stuff */
  120.  
  121. #if defined(MIPS)
  122. #ifdef sony_news
  123. #include <machine/sysnews.h>
  124. #    define FlushICache(addr, size)      \
  125.         sysnews(NEWS_CACHEFLUSH, addr, size, FLUSH_ICACHE)
  126. /* SYS_sysnews will be defined in syscall.h, in OS 4.1 */
  127. #undef SYS_sysnews
  128. #else
  129. #ifndef MACH
  130. #include <sys/sysmips.h>
  131. #endif
  132. #include <errno.h>
  133. extern int errno;        /* some header files are missing this decl */
  134. #  ifdef SGI
  135. /* NOTE: need to flush both caches on R4000 machines, since the
  136.  * primary data cache is write-back.
  137.  */
  138. #  include <sys/cachectl.h>
  139. #  define  FlushICache(addr, size)    \
  140.     (cacheflush((void *)(addr), size, BCACHE))
  141. #  else
  142. #    include <sys/syscall.h>
  143. #    include <mips/cachectl.h>
  144. #    ifdef MACH
  145. #    define MIPS_CACHEFLUSH 0x104
  146. #    endif
  147. #    define FlushICache(addr, size)      \
  148.         (syscall(SYS_sysmips, MIPS_CACHEFLUSH, (addr), (size), ICACHE, 0))
  149. #  endif
  150. #endif
  151. #else
  152. #ifdef NeXT
  153. #  define FlushICache(addr, size)     asm ("trap #2")
  154. #else
  155. #ifdef RS6000
  156.    extern FlushICache();
  157.    extern iCacheLineSize();
  158. #else
  159. #ifdef SPARC
  160.    extern FlushICache();
  161. #else
  162. #ifdef HPPA
  163. #  define FlushICache(addr, size) flush_icache(addr, size)
  164. #else
  165. #ifdef THINK_C
  166. #  define FlushICache(addr, size)     FlushCacheRange((void *)(addr), size)
  167. #else
  168. #  define FlushICache(addr, size)
  169. #endif
  170. #endif
  171. #endif
  172. #endif
  173. #endif
  174. #endif
  175.  
  176.  
  177. #if defined(MACH) && defined(MIPS)
  178.  
  179.    /* Definitions for MIPS-based machines running Mach emulating 4.3bsd */
  180.  
  181. #    define STYP_RDATA    0x100        /* section contains read only data */
  182. #    define STYP_SDATA    0x200        /* section contains small data only */
  183. #    define STYP_SBSS    0x400        /* section contains small bss only */
  184. #    define STYP_LIT8    0x08000000    /* literal pool for 8 byte literals */
  185. #    define STYP_LIT4    0x10000000    /* literal pool for 4 byte literals */
  186. #    define STYP_INIT    0x80000000    
  187.  
  188. #endif
  189.  
  190. /** Reading directories **/
  191.  
  192.  
  193. #if defined(SUNOS) || defined(SGI)
  194. #  include <sys/dirent.h>
  195. #  define READDIR(fd,buf,sz)    getdents((fd), (buf), (sz))
  196.    typedef struct dirent DIR_ENTRY_TY;
  197. #else /* !SUNOS && !SGI */
  198. #  if defined(HPUX)
  199. #    include <sys/param.h>
  200.     /* the following are for <ndir.h> */
  201. #    define LONGFILENAMES
  202. #    define DIRSIZ_MACRO
  203. #    include <ndir.h>
  204. #  else /* !SUNOS && !SGI !HPUX */
  205. #    ifdef AUX
  206. #      include <limits.h>
  207. #    endif
  208. #ifdef THINK_C
  209. #define getdirentries getdirentries_e
  210. #else
  211. #include <sys/dir.h>
  212. #endif THINK_C
  213. #  endif /* HPUX */
  214. #  if defined (AIX)
  215.     /** wonder how long getdirent will be supported? **/
  216. #    define READDIR(fd,buf,sz)    getdirent((fd), (buf), (sz))
  217. #  else /* !SUNOS && !SGI && !AIX */
  218.      static long dummy;
  219. #    define READDIR(fd,buf,sz)      getdirentries((fd), (buf), (sz), &dummy)
  220. #  endif /* AIX */
  221.    typedef struct direct DIR_ENTRY_TY;
  222. #endif /* SUNOS SGI */
  223.  
  224. #ifndef DIRBLKSIZ
  225. #define DIRBLKSIZ 512
  226. #endif /* !DIRBLKSIZ */
  227.  
  228. #if defined(BSD) || defined(RISCos) || defined(HPUX) || defined(SGI) || defined(AUX)
  229. #define HAS_WRITEV
  230. #include <sys/uio.h>
  231. #define HAS_NONBLOCKING_IO
  232. #endif
  233.  
  234. #ifdef NeXT
  235. extern void *get_edata(), *get_etext();
  236. # define EDATA                ((int)get_edata())
  237. # define ETEXT                ((int)get_etext())
  238. #else
  239. #ifdef AIX
  240. extern int _edata, _etext;
  241. #define EDATA              ((int)&_edata)
  242. #define ETEXT              ((int)&_etext)
  243. #else
  244. #ifdef THINK_C
  245. extern int get_edata(), get_etext();
  246. # define EDATA                ((int)get_edata())
  247. # define ETEXT                ((int)get_etext())
  248. #else
  249. extern int edata, etext;
  250. # define EDATA                ((int)(&edata))
  251. # define ETEXT                ((int)(&etext))
  252. #endif
  253. #endif
  254. #endif
  255.  
  256. #endif /* !_ML_OS_ */
  257.